﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Business = SoTaiChinh.Library.Business;
using Entity = SoTaiChinh.Library.Entity;
using Common = SoTaiChinh.Library.Common;

public partial class templates_admin_usercontrols_thamdoykien : System.Web.UI.UserControl
{
    Entity.ThamDoYKien clsE_ThamDoYKien = new SoTaiChinh.Library.Entity.ThamDoYKien();
    Entity.TraLoiYKien clsE_TraLoiYKien = new SoTaiChinh.Library.Entity.TraLoiYKien();
    Business.ThamDoYKien clsB_ThamDoYKien = new SoTaiChinh.Library.Business.ThamDoYKien();
    Business.TraLoiYKien clsB_TraLoiYKien = new SoTaiChinh.Library.Business.TraLoiYKien();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected bool Check()
    {
        bool check = true;
        if (txtCauHoi.Text == "")
        {
            lblCauHoi.Visible = true;
            lblThongBao.Visible = false;
            txtCauHoi.Focus();
            check = false;
        }
        else if (txtCauTraLoi.Text == "")
        {
            lblTraLoi.Visible = true;
            lblThongBao.Visible = false;
            txtCauTraLoi.Focus();
            check = false;
        }
        else if (txtCauTraLoi.Text != "" && txtCauHoi.Text != "")
        {
            lblTraLoi.Visible = false;
            lblCauHoi.Visible = false;
            lblThongBao.Visible = true;
            check = true;
        }
        return check;
    }

    protected void btnThem_Click(object sender, EventArgs e)
    {
        try
        {
            if (Check())
            {
                bool save = false;
                clsE_ThamDoYKien.CauHoi = txtCauHoi.Text;
                clsE_ThamDoYKien.TrangThai = true;
                save=clsB_ThamDoYKien.Insert(clsE_ThamDoYKien);
                String[] strTraLoi = txtCauTraLoi.Text.Split(new string[] { "\r\n" }, StringSplitOptions.None);
                foreach (string str in strTraLoi)
                {
                    clsE_TraLoiYKien.TraLoi = str;
                    clsE_TraLoiYKien.BinhChon = 0;
                    save = clsB_TraLoiYKien.Insert(clsE_TraLoiYKien);
                }
                if (save)
                {
                    Alert.Show("Tạo mới thăm dò ý kiến thành công");
                }
                else
                {
                    Alert.Show("Tạo mới thăm dò ý kiến không thành công");
                }
            }
        }
        catch (Exception ex)
        { }
    }
}
